package com.qiao.startapp;

import android.content.Context;
import androidx.multidex.MultiDex;

import com.alibaba.android.arouter.BuildConfig;
import com.alibaba.android.arouter.launcher.ARouter;
import com.blankj.utilcode.util.SPStaticUtils;
import com.qb.common.base.CommomApplication;
import com.qb.common.bean.UserInfo;
import com.qb.common.constant.Constants;
import com.qb.common.utils.LitePalUtils;

import org.litepal.LitePal;

import java.security.SecureRandom;
import java.security.cert.X509Certificate;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

/**
 * @ProjectName: StartApp
 * @Package: com.qiao.startapp
 * @ClassName: BaseApplication
 * @Description: 类作用描述
 * @Author: qb
 * @CreateDate: 2020/12/11 0011 下午 15:54
 * @UpdateUser: 更新者
 * @UpdateDate: 2020/12/11 0011 下午 15:54
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class MyApplication extends CommomApplication {
    private static final String TAG = "startApp";
    public static MyApplication application;
    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(base);
    }

    @Override
    public void onCreate() {
        super.onCreate();
        application = this;
        handleSSLHandshake();
        //查询补丁 不查询补丁了
//        if ((Utils.getHotfixTime(this)) && isMainProcess()) {
//            SophixManager.getInstance().queryAndLoadNewPatch();
//        }
        //jpush_init_start
        if (BuildConfig.DEBUG){
            ARouter.openLog();
            ARouter.openDebug();
        }
        ARouter.init(this);
        LitePal.initialize(this);
        UserInfo userInfo = new UserInfo();
        userInfo.setUsername("123");
        userInfo.setPassword("123");
        LitePalUtils.INSTANCE.initAddUser(userInfo);

    }
    public static void handleSSLHandshake() {
        try {
            TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
                public X509Certificate[] getAcceptedIssuers() {
                    return new X509Certificate[0];
                }

                @Override
                public void checkClientTrusted(X509Certificate[] certs, String authType) {

                }

                @Override
                public void checkServerTrusted(X509Certificate[] certs, String authType) {

                }
            }};
            SSLContext sc = SSLContext.getInstance("TLS");
            // trustAllCerts信任所有的证书
            sc.init(null, trustAllCerts, new SecureRandom());
            HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
            HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
                @Override
                public boolean verify(String hostname, SSLSession session) {
                    return true;
                }
            });
        } catch (Exception ignored) {

        }
    }
}
